Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conn: Implement driver.Validator, SessionResetter for cancelation #1079

Merged
merged 3 commits into from
Apr 14, 2023
Merged

conn: Implement driver.Validator, SessionResetter for cancelation #1079

merged 3 commits into from
Apr 14, 2023

Conversation

evanj
Copy link
Contributor

@evanj evanj commented Apr 15, 2022

Commit 8446d16 released in 1.10.4 changed how some cancelled query
errors were returned. This has caused a lib/pq application I work on
to start returning "driver: bad connection". This is because we were
cancelling a query, after looking at some of the rows. This causes a
"bad" connection to be returned to the connection pool.

To prevent this, implement the driver.Validator and
driver.SessionResetter interfaces. The database/sql/driver package
recommends implementing them:

"All Conn implementations should implement the following interfaces:
Pinger, SessionResetter, and Validator"

Add two tests for this behaviour. One of these tests passed with
1.10.3 but fails with newer versions. The other never passed, but
does after this change.

Commit 8446d16 released in 1.10.4 changed how some cancelled query
errors were returned. This has caused a lib/pq application I work on
to start returning "driver: bad connection". This is because we were
cancelling a query, after looking at some of the rows. This causes a
"bad" connection to be returned to the connection pool.

To prevent this, implement the driver.Validator and
driver.SessionResetter interfaces. The database/sql/driver package
recommends implementing them:

"All Conn implementations should implement the following interfaces:
Pinger, SessionResetter, and Validator"

Add two tests for this behaviour. One of these tests passed with
1.10.3 but fails with newer versions. The other never passed, but
does after this change.
@jimenez
Copy link

jimenez commented Aug 8, 2022

👍

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! i think this will fix the concern raised in this comment #1000 (comment)

just had a small comment

conn.go Outdated
}

func (cn *conn) IsValid() bool {
// panic("TODO IsValid")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Embarrassing! Thanks for noticing. Removed.

@evanj
Copy link
Contributor Author

evanj commented Jan 29, 2023

Sorry for the massive delay. I must have lost the github notification on the PR. I have merged the latest master, and have fixed the code review comment above. Thanks!

@timbunce
Copy link

timbunce commented Apr 3, 2023

@rafiss can your request for changes be removed now that @evanj addressed your concerns?

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the contribution!

@fho
Copy link

fho commented Apr 18, 2023

@evanj thanks for the fix, we ran into the same issue recently

@otan otan mentioned this pull request Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants